package com.monitorRoutine.monitorRoutineServer.entity;

import lombok.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Builder
@ToString
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class SqlResultVo {
    private String sqlResultId;
    private String setname;
    private String sqlRecordId;
    private String sqlField;
    private String sqlResult;
    private Date time;
    private SqlRecord sqlRecord;

    public SqlResultVo(SqlResult sqlResult, SqlRecord sqlRecord) {
        this(sqlResult);
        this.sqlRecord = sqlRecord;
    }

    public SqlResultVo(SqlResult sqlResult) {
        this.sqlResultId = sqlResult.getSqlResultId();
        this.sqlRecordId = sqlResult.getSqlRecordId();
        this.sqlField = sqlResult.getSqlField();
        this.sqlResult = sqlResult.getSqlResult();
        this.time = sqlResult.getTime();
        this.setname = sqlResult.getSetname();
    }
    public static List<SqlResultVo> SqlResultchangeVoList(List<SqlResult> sqlResults,
                                                          List<SqlRecord> sqlRecords,boolean idSame){
        ArrayList<SqlResultVo> sqlResultVos = new ArrayList<>();
        if (sqlRecords.size()!=sqlResults.size()) {
            idSame=false;
        }
        if (idSame) {
            for (int i = 0; i < sqlResults.size(); i++) {
                SqlResultVo sqlResultVo = new SqlResultVo(sqlResults.get(i), sqlRecords.get(i));
                sqlResultVos.add(sqlResultVo);
            }
        }else {
            for (SqlResult sqlResult : sqlResults) {
                for (SqlRecord sqlRecord : sqlRecords) {
                    if (sqlRecord.getSqlRecordId().equals(sqlResult.getSqlRecordId())) {
                        SqlResultVo sqlResultVo = new SqlResultVo(sqlResult,sqlRecord);
                        sqlResultVos.add(sqlResultVo);
                        continue;
                    }
                }
            }
        }
        return sqlResultVos;
    }
}
